from rest_framework.viewsets import ModelViewSet
from rest_framework.response import Response
from system.serializers import Menu
from system import models
from system.filters import MenuFilters


class MenuView(ModelViewSet):
	queryset = models.Menu.objects.order_by("-id")
	serializer_class = Menu.MenuSerializers
	filterset_class = MenuFilters.MenuFilter

	def list(self, request, *args, **kwargs):
		queryset = self.filter_queryset(self.get_queryset()).filter(pid=0)

		page = self.paginate_queryset(queryset)
		if page is not None:
			serializer = self.get_serializer(page, many=True)
			return self.get_paginated_response(serializer.data)

		serializer = self.get_serializer(queryset, many=True)
		return Response(serializer.data)
